package math.base;

/**
 * @author Saga
 *
 */
public class Dir3d {
    public Dir3d() {
        this.coord = new Coord3d(1.0, 0.0, 0.0);
    }

    public Dir3d(final double _x, final double _y, final double _z) {
        final double mag = Math.sqrt(_x * _x + _y * _y + _z * _z);
        final double scalar = 1.0 / mag;
        this.coord = new Coord3d(_x * scalar, _y * scalar, _z * scalar);
    }

    public Dir3d(final Coord3d _coord) {
        this.coord = _coord.normalized();
    }

    public Dir3d(final Vector3d _vec) {
        this.coord = _vec.getCoord().normalized();
    }

    //coord
    public final void setNormalizedCoord(final Coord3d _coord) {
        this.coord = _coord;
    }

    public final void setNormalizedCoord(final double _x, final double _y, final double _z) {
        this.coord.init(_x, _y, _z);
    }

    public final void setCoord(final Coord3d _coord) {
        this.coord = _coord.normalized();
    }

    public final Coord3d getCoord() {
        return this.coord;
    }

    public final void setCoord(final double _x, final double _y, final double _z) {
        this.coord = new Coord3d(_x, _y, _z);
        this.coord.normalize();
    }

    public final double getX() {
        return this.coord.getX();
    }

    public final double getY() {
        return this.coord.getY();
    }

    public final double getZ() {
        return this.coord.getZ();
    }

    //reverse
    public final void reverse() {
        this.coord.reverse();
    }

    public final Dir3d reversed() {
        return new Dir3d(this.coord.reversed());
    }

    //multiply
    public final Vector3d multiplied(final double _scalar) {
        return new Vector3d(this.coord.multiplied(_scalar));
    }

    //product
    public final double dot(final Dir3d _dir) {
        return this.coord.dot(_dir.getCoord());
    }

    public final Vector3d crossed(final Dir3d _dir) {
        return new Vector3d(this.coord.crossed(_dir.getCoord()));
    }

    @Override
    public final Dir3d clone() {
        final Dir3d output = new Dir3d();
        output.setNormalizedCoord(this.coord.clone());
        return output;
    }

    private Coord3d coord;
}
